package ru.ifmo.trafficspy.provider;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ru.ifmo.trafficspy.common.Interval;
import ru.ifmo.trafficspy.common.Item;
import ru.ifmo.trafficspy.common.Packet;

public class SecondProvider extends Provider {

	private static Random random = new Random();
	
	private final int n;
	private ArrayList<Item> traffic;
	
	private int randomRange(int l, int r) {
		return l + random.nextInt(r - l + 1);
	}
	
	private void addPacket() {
		if (random.nextDouble() <= 0.1) {
			traffic.add(new Packet(randomRange(1000, 2500)));
		} else {
			traffic.add(new Packet(randomRange(500, 2000)));
		}
	}

	private void addGap() {
		traffic.add(new Interval(randomRange(10, 20)));
	}
	
	public SecondProvider(int n) {
		super("first provider");
		this.n = n;
	}
	
	@Override
	public List<Item> getTraffic() {
		traffic = new ArrayList<Item>();
		addPacket();
		for (int i = 0; i < 2 * n - 1; i++) {
			addGap();
			addPacket();
		}
		return traffic;
	}

}
